<?php

/** Class that build calendars for events
 * 
 * @author Ziyad (MySchizoBuddy) Saeed
 * @copyright 2007 Ziyad Saeed
 * @license http://lussumo.com/community/gpl.txt GPL 2
 * @package Vcal
 * @version 0.1
 */

class Calendars {
	/**
	* Unique identifier of each calendar type
	* @access public
	* @var int
	*/
	var $CalendarID;
	
	/**
	* Title of calendar
	* @access public
	* @var string
	*/
	var $Title;
	
	/**
	* A brief description of what the calendar is about
	* @access public
	* @var string
	*/
	var $Description;
	
	/**
	* Is this Calendar blocked by the viewing user
	* @access public
	* @var bool
	*/
	var $Blocked;

	/**
	* Is this Calendar blocked to the role of the viewing user
	* @access public
	* @var bool
	*/
	var $RoleBlocked;

	/**
	* Contains the roles that are allowed to take part in this Calendar
	* @access public
	* @var array
	*/	
	var $AllowedRoles;

	/**
	* How many events belong to a particular calendar - aggregate display only
	* @access public
	* @var int
	*/
	var $EventCount;
	
	/**
	* Color associated with each calendar, background, border, text and time color of its events. This is what is displayed
	* @access public
	* @var array
	*/	
	var $ColorArr;
	
	/**
	* Serialized Color associated with each calendar, background, border, text and time color of its events. This is what gets stored in the database
	* @access public
	* @var string
	*/	
	var $ColorStr;
	
	/**
	* Do events in this calendar require admin approval
	* @access public
	* @var bool
	*/	
	var $RequireApproval;
	
	/**
	* Constructor
	*/
	function Calendars() {
		$this->Clear();
	}

	/**
	* Clears all members to their default values
	*
	* @return void
	*/
	function Clear() {
		$this->CalendarID = 0;
		$this->Title = '';
		$this->Description = '';
		$this->EventCount = 0;
		$this->Blocked = 0;
		$this->RoleBlocked = 0;
		$this->AllowedRoles = array();
		$this->ColorArr = array();
		$this->ColorStr = '';
		$this->RequireApproval = 0;
	}
	
	/**
	* Gets calendar specific properties from a dataset
	*
	* @param array $Dataset 
	* @return void
	*
	* <b>Usage example:</b>
	* <code>
	* $Calendar = $Context->ObjectFactory->NewObject($Context, 'Calendars');
	* // Do your queries here
	* while ($rows = $Context->Database->GetRow($ResultSet)) {
	*		$Calendar->GetPropertiesFromDataSet($rows);
	* }
	* </code>
	*/
	function GetPropertiesFromDataSet($DataSet) {
		$this->CalendarID = ForceInt(@$DataSet['CalendarID'], 0);
		$this->Title = ForceString(@$DataSet['Title'], '');
		$this->Description = ForceString(@$DataSet['Description'], '');
		$this->EventCount = ForceInt(@$DataSet['EventCount'], 0);
		$this->Blocked = ForceBool(@$DataSet['Blocked'], 0);
		$this->RoleBlocked = ForceBool(@$DataSet['RoleBlocked'], 0);
		$this->RequireApproval = ForceBool(@$DataSet['RequireApproval'], 0);
		$this->ColorStr = ForceString(@$DataSet['Color'], '');
	}
	
	/**
	* Format calendar specific properties for display. Clean up malicious information as well
	*
	* @return void
	*
	* <b>Usage example:</b>
	* <code>
	* $Calendar = $Context->ObjectFactory->NewObject($Context, 'Calendars');
	* $Calendar->FormatPropertiesForDisplay();
	* </code>
	*/
	function FormatPropertiesForDisplay() {
		$this->Title = FormatStringForDisplay($this->Title, 1);
		$this->Description = FormatStringForDisplay($this->Description, 1);
		$this->ColorArr = UnserializeAssociativeArray($this->ColorStr);
	}
	
	/**
	* Get form elements
	*
	* @return void
	*
	* <b>Usage example:</b>
	* <code>
	* $Calendar = $Context->ObjectFactory->NewObject($Context, 'Calendars');
	* $Calendar->GetPropertiesFromForm();
	* </code>
	*/
	function GetPropertiesFromForm(&$Context) {
		$this->CalendarID = ForceIncomingInt('CalendarID', 0);
		$this->Title = ForceIncomingString('Title', '');
		$this->Description = ForceIncomingString('Description', '');
		$this->AllowedRoles = ForceIncomingArray('CalendarRoleBlock', array());
		$this->ColorArr = ForceIncomingArray('ColorArr', array());
		$this->RequireApproval = ForceIncomingInt('RequireApproval', 0);
	}

	/**
	* Format properties for database input
	*
	* @return void
	*
	* <b>Usage example:</b>
	* <code>
	* $Calendar = $Context->ObjectFactory->NewObject($Context, 'Calendars');
	* $Calendar->FormatPropertiesForDatabaseInput();
	* </code>
	*/	
	function FormatPropertiesForDatabaseInput() {
		$this->Title = FormatStringForDatabaseInput($this->Title, 1);
		$this->Description = FormatStringForDatabaseInput($this->Description, 1);
		$this->ColorStr = SerializeArray($this->ColorArr);
	}
}
?>